---
title: On-Off schedule with state persistence
description: A simple on-off schedule, with the addition of state persistence across disruptive events, making sure the target device is always in the expected state.
---

import {
  Input,
  Inputs,
  Requirement,
  ImportCard,
  Changelog,
} from '/src/components/blueprints_docs'

<ImportCard id='on_off_schedule_state_persistence' category='automation' />

<br />

## Description

This blueprint provides a simple on-off schedule, with the addition of state persistence across server reboots, powercuts, or other disruptive events which could potentially alter the expected state of the targeted entities. The automation makes sure the target is always in the expected state, even in these situations, but always leaving the freedom to manually toggle the target state as desired. It can be used on critical targets which require a simple on-off schedule during every single day.

One common scenario where this could be useful is in the case of a server reboot or shutdown. For example, let's assume you've an automation _A_ set to turn on light _L_ at 12:00. If for whatever reason Home Assistant goes offline at 11:59 and turns back on at 12:01, automation _A_ scheduled for 12:00 is not executed, with the result of _L_ not being in the state you'd expect to be, after 12:00.

Using this blueprint in the above example would have guaranteed the expected behaviour, with the automation _A_ being run at Home Assistant startup, and setting the _L_ state as described by the schedule.

Examples of disruptive scenarios could include server reboots, network outages or powercuts. Since every installation could be influenced by many different events and check for them in many different ways, the blueprints includes the flexibility to optionally supply a custom event type which the automation will listen to. When such event is fired, the automation is run.

The blueprint already implements the support for listening to Home Assistant startup events, but this functionality can be disabled as desired by the user.

Internally, the blueprint calculates time ranges based on the provided On-Off times, bound to the target expected state. Whenever one of the specified times is reached or a disruptive event occurs, the automation retrieves the expected state from the calculated ranges, and enforces it on the target.

## Requirements

No additional integrations or addons are required for this blueprint, since it's only based on the [Home Assistant Core Integration](https://www.home-assistant.io/integrations/homeassistant).

If you optionally want to supply a custom event type to the blueprint, you should setup a mechanism to fire the event in any situation a state check should be performed. This could be an integration firing an event, or another automation, so any additional required setup is out of scope of this documentation.

## Inputs

<Inputs category='automation' id='on_off_schedule_state_persistence' />

## Additional Notes

This automation only provides a simple On-Off schedule. More complex situations could require a different approach to the problem. Also, be aware that running multiple automations generated with this blueprint against the same target could result in unexpected behaviour.

## Changelog

<Changelog category='automation' id='on_off_schedule_state_persistence' />
